package com.yue.okhttp.simple_example;

import okhttp3.*;

import java.io.IOException;

/**
 * Created by qiuyang on 21/02/2017.
 */
public class PostExample {
    private OkHttpClient client = new OkHttpClient();

    public static final MediaType JSON = MediaType.parse("application/json;charset=utf-8");

    public String post(String url, String json) throws IOException {
        RequestBody requestBody = RequestBody.create(JSON, json);

        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();

        Response response = client.newCall(request).execute();
        return response.toString();
    }
}
